/**
 * create by young (young2f@outlook.com) on 2020/9/16
 */


'use strict';
import React from 'react';
import {Button, Form, InputNumber, notification} from 'antd';

import FormBase from '../../../components/Base/FormBase';
import {connect} from "dva";
import moment from 'moment';
import 'moment/locale/zh-cn';
import {FormField, FormLayout, ModalFooter} from "antd-extra";

moment.locale('zh-cn');
const table = 'SalesOrder';
@Form.create()
@connect(({
            user,
            global,
            dynamicLabel,
            material,
            store
          }) => ({...user, ...material, ...dynamicLabel, ...global, ...store}))
export default class ModalEditUsedMaterialLotCount extends FormBase {
  constructor(props) {
    super(props);
    this.state = undefined;
  }

  componentDidMount() {

  }

  renderFoot = () => {
    const {foot, value, modalRef, form, callback, useMaterials = [], materialRecords = []} = this.props;
    if (foot) {
      return foot(value, modalRef);
    } else {
      return (
        <ModalFooter>
          <Button type="primary" onClick={() => {
            const {modalRef} = this.props;
            form.validateFields((err, values) => {
              if (err) {
                const {code} = err;
                const {errors} = code;
                errors.forEach(item => {
                  notification.error(item);
                });
                return;
              }

              callback(values);
              modalRef.close();
            });
          }}>确定</Button>
          <Button onClick={() => {
            modalRef.close();
          }}>取消</Button>
        </ModalFooter>
      );
    }
  };

  render() {
    const {form, usedCount, style} = this.props;
    return <div style={{...style}}>
      <FormLayout form={form} cols={2}>
        <FormField
          label={'占用数量（KG)'}
          required={true}
          name={'usedCount'} initialValue={usedCount}
        >
          <InputNumber style={{width: '100%'}}></InputNumber>
        </FormField>
      </FormLayout>
      {this.renderFoot()}
    </div>;
  }
}
